{include file="common/header-top" /}

<style>
    .van-grid-item__text{
        white-space: nowrap;
        text-overflow: ellipsis;
    }

    .job-item{
        display: block;
        margin-top: 5px;
    }

    .job-item-a{
        color: #2f2d33;
    }

    .job-item .job-item-img-icon {
        margin-top: 28px;
        padding-left: 10px;
    }

    .job-item .job-item-title{
        margin: 8px 0px 5px 2px;
        color: #3c3c3c;
        text-overflow: ellipsis;
        font-size: 15px;
        font-weight: 600;
        -webkit-line-clamp: 2;
    }
    .job-item .job-item-icon{
        font-size: small;
    }
    .job-item .job-item-span{
        color: #949595;
        font-weight: 500;
        font-size: 12px;
        padding-left: 5px;
    }
    .job-item .job-item-span-unit{
        font-size: 14px;
        color: #fcc48d;
    }

    .job-item .job-item-money-div{
        margin-top: 45px;
        float: right;
        margin-right: 5px;
    }


    .job-item .van-cell{
        padding: 0;
    }

    .job-item .van-cell:not(:last-child)::after{
        border-bottom: 0;
    }


</style>


<div id='app' v-cloak>

    <van-nav-bar title="我的二手商品" left-arrow @click-left="goBack" left-text="返回">
    </van-nav-bar>


    <van-tabs v-model="currentTab" swipeable @click="changeTab">
        <van-tab title="全部" name="0"></van-tab>
        <van-tab title="审核中" name="2"></van-tab>
        <van-tab title="展示中" name="3"></van-tab>
        <van-tab title="审核失败" name="4"></van-tab>
        <van-tab title="草稿箱" name="1"></van-tab>
    </van-tabs>

    <van-row>


        <!--二手商品列表-->
        <van-list
                v-model="loading"
                :finished="finished"
                finished-text="没有更多了"
                @load="getPublishGoodsList"
        >

            <van-row v-for="item in goodsList" class="job-item">
                <van-card
                        :num="item.number"
                        :title="item.name"
                        :thumb="item.logo"
                        :price="item.money"
                        :origin-price="item.oprice"
                        @click="goGoodsDetail(item)"
                >
                    <div slot="tags">
                        <van-tag type="success">{{item.statusCh}}</van-tag>
                    </div>
                    <div slot="footer">
                        <van-button
                                size="small"
                                type="primary"
                                @click.stop="editGoods(item)"
                                v-if="canEdit(item)"
                        >编辑商品</van-button>
                        <van-button
                                size="small"
                                type="danger"
                                @click.stop="delGoods(item)"
                        >下架商品</van-button>

                    </div>
                </van-card>
            </van-row>



        </van-list>
        <!--二手商品列表-->
    </van-row>





    {include file="common/foot-bar" /}

</div>


<script>

    Vue.use(vant.Lazyload);

    var vm = new Vue({
        el: '#app',
        data() {
            return {
                active:3,
                userCenterIcon: {
                    normal: '/__FRONT__/images/icon/usercenter-n.png',
                    active: '/__FRONT__/images/icon/usercenter-a.png'
                },
                erShouIcon: {
                    normal: '/__FRONT__/images/icon/ershou-n.png',
                    active: '/__FRONT__/images/icon/ershou-a.png'
                },


                //当前列表类型
                currentType: '{$type}',
                currentTab: '{$type}',
                page: 1,
                pageSize: 8,


                //兼职列表集
                goodsList: [],
                loading: false,
                finished: false


            };
        },
        created(){

        },

        computed:{

        },

        methods:{
            //返回上一页
            goBack(){
                history.back();
            },
            //判断能否编辑
            canEdit(item){
                if (item.status == 1 || item.status == 4) {
                    return true;
                }
                return false;
            },


            /**==========二手商品操作============*/
            //编辑二手商品
            editGoods(item){
                window.location.href = '/index/Market/publishGoods?goodsId=' + item.id;
            },
            //删除二手商品
            delGoods(item){
                var params = {
                    id: item.id,
                };
                axiosRequest.post('/api/user/delGoods', params).then(function (response) {
                    if (response.code == 200) {
                        vm.$data.goodsList.forEach(function (one, index) {
                            if (one.id == response.data.goodsId) {
                                vm.$data.goodsList.splice(index, 1);
                            }
                        });
                        vant.Toast('操作成功！');
                    } else {
                        vant.Toast('系统开小差啦！');
                    }
                });
            },
            /**==========二手商品操作============*/




            //切换tab
            changeTab(name, title){
                this.currentType = name;
                this.goodsList = [];
                this.page = 1;
                this.pageSize = 8;
                this.loading = true;
                this.finished = false;
                this.getPublishGoodsList();
            },
            //获取我发布的二手商品
            getPublishGoodsList(){
                var params = {
                    type: this.currentType,
                    page: this.page,
                    pageSize: this.pageSize
                };
                axiosRequest.get('/api/user/myPublishMarket', {params:params}).then(function (response) {
                    if (response.code == 200) {
                        if (response.data) {
                            response.data.forEach(function (item) {
                                vm.$data.goodsList.push(item);
                            });
                            vm.$data.loading = false;
                            vm.$data.page += 1;

                            if (response.data.length < vm.$data.pageSize) {
                                vm.$data.finished = true;
                                vm.$data.loading = false;
                            }
                        } else {
                            vant.Toast('没有更多啦！');
                            vm.$data.finished = true;
                            vm.$data.loading = false;
                        }
                    } else {
                        vant.Toast('系统开小差啦！');
                    }
                });
            },

            goGoodsDetail(item){
                window.location.href = '/index/Market/goodsDetail?id=' + item.id;
            }

        }
    });


</script>







{include file="common/foot-bottom" /}
